package com.cn.crmsystem.controller.customerController;

import com.cn.crmsystem.pojo.*;
import com.cn.crmsystem.service.customerService.OppService;
import io.swagger.annotations.*;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@Api(value ="商机数据test",tags ="商机数据接口API")
public class OppController {

    @Autowired
    private OppService oppService;

    //获取登录的用户pojo对象
    //User user = (User) SecurityUtils.getSubject().getPrincipal();
    @ResponseBody
    @RequestMapping(value = "/insertOpp",method = RequestMethod.POST)
    @ApiOperation(value ="新增商机数据接口",notes = "填写商机基本数据",httpMethod = "POST",response = ResultJson.class)
    @ApiParam(name = "opportunity",value = "商机基本信息",required = false)
    public ResultJson insertOpp(@RequestBody Opportunity opportunity){
        //User user = (User) SecurityUtils.getSubject().getPrincipal();
         Login login = (Login) SecurityUtils.getSubject().getPrincipal();
//        Login login =new Login();
//        login.setUser_id(1);
        System.out.println(login.getUser_id());
        return  oppService.insertOpp(opportunity,login);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteOpp",method = RequestMethod.POST)
    @ApiOperation(value ="删除商机数据接口",notes = "传入要删除的数据id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "商机数据id",required = false,dataType = "Integer",paramType = "query")
    public ResultJson deleteOpp(Integer id){
        System.out.println(id);
        return oppService.deleteOpp(id);
    }

    @ResponseBody
    @RequestMapping(value = "/updateOpp",method = RequestMethod.POST)
    @ApiOperation(value ="修改商机数据接口",notes = "填写修改后商机基本数据",httpMethod = "POST",response = ResultJson.class)
    @ApiParam(name = "customer",value = "修改后商机基本信息",required = false)
    public ResultJson updateOpp(@RequestBody Opportunity opportunity) {
        System.out.println(opportunity.getName() + "****");
        //User user = (User) SecurityUtils.getSubject().getPrincipal();
        return oppService.updateOpp(opportunity);
    }

    @ResponseBody
    @RequestMapping(value = "/updateOppUser",method = RequestMethod.POST)
    @ApiOperation(value ="修改商机负责人数据接口",notes = "传入修改后的负责人id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "修改后的负责人id",required = false,dataType = "Integer",paramType = "query")
    public ResultJson updateOppUser(@RequestParam Integer id) {
        return oppService.updateOppUser(id);
    }

    @ResponseBody
    @RequestMapping(value = "/selectOpp",method = RequestMethod.POST)
    @ApiOperation(value ="条件查询商机数据接口",notes = "填写筛选条件数据",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "商机名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "customer_name",value = "线索（客户）名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "opp_state",value = "商机阶段",paramType = "query",dataType = "Integer",required = false),
            @ApiImplicitParam(name = "user_name",value = "负责人名字",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "create_name",value = "创建人名字",paramType = "query",dataType = "String",required = false)
    })
    public ResultJson<List> selectOpp(@RequestBody @RequestParam  @ApiParam(required = false) Map<String,Object> map) {
        return oppService.selectOpp(map);
    }


    @ResponseBody
    @RequestMapping(value = "/deleteAllOpp",method = RequestMethod.POST)
    @ApiOperation(value ="批量删除商机数据接口",notes = "传入要删除的数据id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "ids",value = "商机id",paramType = "query",dataType = "String",required = false)
    public ResultJson deleteAllOpp(Integer[] ids){
        System.out.println(ids.length);
        return oppService.deleteAllOpp(ids);

    }
}
